import 'reflect-metadata';
import { LogOptions } from '@/interfaces';

export const LOG_METADATA = Symbol('log_metadata');

/*
 * 日志装饰器
 * -------------- 何时使用日志 --------------
 * 1. 登录、登出、授权
 * 2. 资金/订单/库存 变动
 * 3. 管理员后台 任何写操作
 * 4. 关键读接口（导出、大批量查询）
 * 5. 用户敏感操作（修改密码、换绑手机）
 * @param opt 日志参数
 * @return void
 */
export function Log(opt: LogOptions) {
  return function (target: any, propertyKey: string) {
    Reflect.defineMetadata(LOG_METADATA, opt, target.constructor, propertyKey);
  };
}

export enum LogBizId {
  /* -------------- 登录/会话 -------------- */
  SIGNUP = 'auth:signup',
  LOGIN = 'auth:login',
  LOGOUT = 'auth:logout',
  /* -------------- 定时任务 -------------- */
  JOB_START = 'task:job_start',
  JOB_END = 'task:job_end',
  JOB_FAIL = 'task:job_fail',
  /* -------------- 系统级事件 -------------- */
  SYS_START = 'system:start',
  SYS_SHUTDOWN = 'system:shutdown',
  /* -------------- 文件/资源 -------------- */
  FILE_UPLOAD = 'resource:upload',
  FILE_DOWNLOAD = 'resource:download',
  FILE_DELETE = 'resource:delete',
  /* -------------- 安全/风控 -------------- */
  PWD_RESET = 'security:pwd_reset',
  // ...
}

export enum LogOperation {
  /* -------------- 登录/会话 -------------- */
  LOGIN = 'LOGIN',
  LOGOUT = 'LOGOUT',
  SIGNUP = 'SIGNUP',
  /* -------------- 系统级事件 -------------- */
  SYS_START = 'START',
  SYS_SHUTDOWN = 'SHUTDOWN',
  /* -------------- 数据库操作 -------------- */
  CREATE = 'CREATE',
  UPDATE = 'UPDATE',
  DELETE = 'DELETE',
  QUERY = 'QUERY',
}
